The TRACE function computes the trace of an n by n array.
This routine is written in the IDL language. Its source code can be found in the file trace.pro in the lib subdirectory of the IDL distribution.
Result = TRACE( A [, /DOUBLE] )
Returns the sum of the values along the array diagonal.
An n by n real or complex array.
Set this keyword to force the computation to be done in double-precision arithmetic.
; Define an array:
A = [[ 2.0,1.0,  1.0, 1.5], $
     [ 4.0, -6.0,  0.0, 0.0], $
     [-2.0,  7.0,  2.0, 2.5], $
     [ 1.0,  0.5,  0.0, 5.0]]
; Compute the trace of A:
result = TRACE(A)
;Print the result:
PRINT, 'TRACE(A) = ', result
IDL prints:
TRACE(A) = 3.00000
| 5.0 | Introduced |